<!DOCTYPE html>
<html lang="en">
<head>
    {include file="common/meta" /}
</head>
<body>
    <div class="x-body">
        <xblock>
          <button class="layui-btn layui-btn-danger" onclick="delAll()">
            <i class="layui-icon"></i>批量删除
          </button>
  
          <span class="x-right" style="line-height:40px">
            共有数据：{$count} 条
          </span>
        </xblock>
  
        <table class="layui-table">
          <thead>
            <tr>
              <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
              </th>
              <th>配置的标题</th>
              <th>配置的名称</th>
              <th>配置的类型</th>
              <th>配置的值</th>
              <th>操作</th>
          </thead>
  
          <tbody>
          {foreach $countlist as $item}
            <tr>
              <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="{$item.id}">
                  <i class="layui-icon">&#xe605;</i>
                </div>
              </td>
              <td>{$item.title}</td>
              <td>{$item.key}</td>
              {if condition = "$item.type == 'text'"}
                <td>文本类型</td>
                <td>{$item.value}</td>
              {else /}
                <td>文件类型</td>
                <td>
                    <img src="{$item.value}" alt="">
                </td>
               {/if}
                <td>
                    <a title="编辑" href="{:url('admin/config/edit', ['id' => $item.id])}">
                        <i class="layui-icon">&#xe642;</i>
                    </a>
                    <a title="删除"href="javascript:;" onclick="deletes(`{$item.id}`)">
                        <i class="layui-icon">&#xe640;</i>
                    </a>
                </td>
            </tr>
            {/foreach}
          </tbody>
        </table>
  
        <div class="page">
            {$pagestr}
        </div>
  
      </div>
</body>
</html>
<script>
    // 批量删除
    function delAll(){
        var ids = tableCheck.getData()
        layer.confirm('确认要删除吗？',function(index){
            //将数组转换为字符串
            var data = ids.join(',');
            del(data)
        })
    }

    // 单个删除
    function deletes(id){
        layer.confirm('确认要删除吗？',function(index){
            layer.close(index);
            del(id)
        })
    }

    // 调用删除方法
    function del(data){
        //序列化 将对象转换为参数形式
        var params ={
            ids: data
        }
       
        params = $.param(params)

        $.ajax({
            type: "POST",
            url: `{:url('admin/config/del')}`,
            data: params,
            dataType: "json",
            success: function(data){
                layer.msg(data.msg,{icon: 5,time:1000},function(){
                    location.reload()
                })
            }
        })
    }
</script>
